package com.util;

/**
 * 出参错误码列表
 * 尽管是后台信息，文案受制于中前台要求，暴露给用户
 * 接手者请推动前端的后台包装，目前谨慎修改
 */
public enum ResultEnum {
    SUCCESS("200", "操作成功！"),
    ERROR("500", "操作异常！"),
    LOGOUT("200", "退出成功！"),
    UNAUTHORIZED("401", "请先登录！"),
    ACCESS_DENIED("403", "权限不足！"),
    REQUEST_NOT_FOUND("404", "请求不存在！"),
    HTTP_BAD_METHOD("405", "请求方式不支持！"),
    BAD_REQUEST("400", "请求异常！"),
    PARAM_NOT_MATCH("400", "参数不匹配！"),
    PARAM_NOT_NULL("400", "参数不能为空！"),
    COMMON_EXCEPTION("500", "系统异常"),
    USER_DISABLED("403", "当前用户已被锁定，请联系管理员解锁！"),
    USERNAME_PASSWORD_ERROR("5001", "用户名或密码错误！"),
    TOKEN_EXPIRED("5002", "token 已过期，请重新登录！"),
    TOKEN_PARSE_ERROR("5002", "token 解析失败，请尝试重新登录！"),
    TOKEN_OUT_OF_CTRL("5003", "当前用户已在别处登录，请尝试更改密码或重新登录！"),
    KICKOUT_SELF("5004", "无法手动踢出自己，请尝试退出登录操作！");

    String code;
    String msg;

    ResultEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }


    public static ResultEnum getByCode(String code) {
        if (code == null) {
            return COMMON_EXCEPTION;
        }
        for (ResultEnum outputEnum : ResultEnum.values()) {
            if (code.equals(outputEnum.code)) {
                return outputEnum;
            }
        }
        return COMMON_EXCEPTION;
    }
}
